<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%
 	   int t=0;
       String classId = request.getParameter("classId");
       String className =  new String(request.getParameter("className").getBytes("ISO8859-1"),"UTF-8");
       String classSize = request.getParameter("classSize");
       try{
       	   Class.forName("com.mysql.jdbc.Driver").newInstance();
       	   Connection con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/classfee", "root", "1234");
       	   Statement stmt = con.createStatement();
       	   ResultSet srt = stmt.executeQuery("SELECT classId FROM  tb_class where classId='"+classId+"'");
       	   while(srt.next())
       	   {
       		   if(srt.getString("classId").equals(classId))
       		   {
       			   t=1;
       			   break;
       		   }
       	   }
       	   if(t==1)
    	       out.println("<script>alert('该编号班级已添加过!');window.location='classadd1.jsp'</script>");
       	   else
       	   {
    	       stmt.executeUpdate("insert into tb_class(classId,className,classSize) values('"+classId+"','" +className+"','"+classSize+"')");
    	       out.println("<script>alert('添加成功!');window.location='classadd1.jsp'</script>");
       	   }
       	   srt.close();
    	   stmt.close();
    	   con.close();
         }
      catch(Exception ex)
      { 
    	   out.println("<script>alert('添加失败!');window.location='classadd1.jsp'</script>");
    	   out.println(ex.getMessage());
      }
	       
%>
